widget-factory: add entry progress modes
authorWilliam Jon McCann <william.jon.mccann@gmail.com>
Wed, 26 Feb 2014 16:16:06 +0000 (11:16 -0500)
committerWilliam Jon McCann <william.jon.mccann@gmail.com>
Wed, 26 Feb 2014 16:16:06 +0000 (11:16 -0500)
demos/widget-factory/widget-factory.c
demos/widget-factory/widget-factory.ui

index ee0e59cfcd2d73f49c504a9d298c27493aa1fa0c..19380a3a87a7dbaf3db62d7e841c8bf3116b5c65 100644 (file)
@@ -163,6 +163,47 @@ update_pulse_time (GtkAdjustment *adjustment, GtkWidget *widget)
     }
 }
 
+static guint pulse_entry_id = 0;
+
+static gboolean
+pulse_entry (GtkEntry *entry)
+{
+  gtk_entry_progress_pulse (entry);
+
+  pulse_entry_id = g_timeout_add (100, (GSourceFunc)pulse_entry, entry);
+
+  return G_SOURCE_REMOVE;
+}
+
+static void
+on_entry_icon_release (GtkEntry            *entry,
+                       GtkEntryIconPosition icon_pos,
+                       GdkEvent            *event,
+                       gpointer             user_data)
+{
+  static int num = 0;
+
+  if (icon_pos != GTK_ENTRY_ICON_SECONDARY)
+    return;
+
+  num++;
+
+  if (num % 3 == 0)
+    {
+      if (pulse_entry_id > 0)
+        g_source_remove (pulse_entry_id);
+      gtk_entry_set_progress_fraction (entry, 0);
+    }
+  else if (num % 3 == 1)
+    gtk_entry_set_progress_fraction (entry, 0.25);
+  else if (num % 3 == 2)
+    {
+      gtk_entry_set_progress_pulse_step (entry, 0.1);
+      pulse_entry (entry);
+    }
+
+}
+
 static void
 startup (GApplication *app)
 {
@@ -192,6 +233,8 @@ activate (GApplication *app)
 
   builder = gtk_builder_new ();
   gtk_builder_add_from_resource (builder, "/ui/widget-factory.ui", NULL);
+  gtk_builder_add_callback_symbol (builder, "on_entry_icon_release", (GCallback)on_entry_icon_release);
+  gtk_builder_connect_signals (builder, NULL);
 
   window = (GtkWindow *)gtk_builder_get_object (builder, "window");
   gtk_application_add_window (GTK_APPLICATION (app), window);
index 17a9008763e5c98a86e7b6437a7414be63dfa268..cb6b0c81dd5cf5b552891f2069be5fa4e946fe58 100644 (file)
@@ -206,7 +206,9 @@ Suspendisse feugiat quam quis dolor accumsan cursus. </property>
                             <property name="visible">True</property>
                             <property name="can_focus">True</property>
                             <property name="invisible_char">•</property>
-                            <property name="text" translatable="yes">entry</property>
+                            <property name="placeholder-text" translatable="yes">Click icon to change mode</property>
+                            <property name="secondary_icon_name">view-refresh-symbolic</property>
+                            <signal name="icon-release" handler="on_entry_icon_release" swapped="no"/>
                           </object>
                           <packing>
                             <property name="expand">False</property>